Trò chơi 2D Cow Boy Runner

52.963 lượt xem;
1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class ObjectPooler : MonoBehaviour {
6
7     
public GameObject pooledObject;
8
9     
public int pooledAmount;
10
11     List<GameObject> pooledObjects;
12
13     
void Start () {
14         pooledObjects =
new List<GameObject> ();
15
16         
for(int i = 0; i < pooledAmount; i++) {
17             GameObject obj = (GameObject)Instantiate (pooledObject);
18             obj.SetActive (
false);
19             pooledObjects.Add (obj);
20         }
21     }
22     
23     
public GameObject GetPooledObject () {
24         
for(int i = 0; i < pooledObjects.Count; i++) {
25             
if(!pooledObjects[i].activeInHierarchy) {
26                 
return pooledObjects[i];
27             }
28         }
29
30         GameObject obj = (GameObject)Instantiate (pooledObject);
31         obj.SetActive (
false);
32         pooledObjects.Add (obj);
33
34         
return obj;
35     }
36 }


Gõ tìm kiếm nhanh...